package com.pig4cloud.pigx.ruralLibrary.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pig4cloud.pigx.admin.api.dto.UserInfo;
import com.pig4cloud.pigx.admin.api.entity.SysRole;
import com.pig4cloud.pigx.admin.api.entity.SysUserRole;
import com.pig4cloud.pigx.admin.api.feign.RemoteUserService;
import com.pig4cloud.pigx.common.core.constant.SecurityConstants;
import com.pig4cloud.pigx.common.core.util.R;
import com.pig4cloud.pigx.common.security.util.SecurityUtils;
import com.pig4cloud.pigx.ruralLibrary.api.dto.ResourceAuditDto;
import com.pig4cloud.pigx.ruralLibrary.api.entity.BookUserEntity;
import com.pig4cloud.pigx.ruralLibrary.api.entity.ResourceAudit;
import com.pig4cloud.pigx.ruralLibrary.service.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpHeaders;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;


/**
 * <p>
 * 资源审核中间表 前端控制器
 * </p>
 *
 * @author ccl
 * @since 2025-02-18
 */
@RestController
@RequiredArgsConstructor
@RequestMapping("/resource-audit")
@Tag(description = "发布审核", name = "发布审核相关接口")
@SecurityRequirement(name = HttpHeaders.AUTHORIZATION)
public class ResourceAuditController {
	private final ResourceAuditService resourceAuditService;

	private final BookUserService bookUserService;


	@Operation(summary = "分页查询", description = "分页查询")
    @GetMapping("/queryPage")
	@PreAuthorize("@pms.hasPermission('ruralLibrary_user_view')")
    public R queryPage(Page page, ResourceAuditDto dto) {
		LambdaQueryWrapper<ResourceAudit> wrapper = Wrappers.lambdaQuery();
		wrapper.eq(StrUtil.isNotBlank(dto.getAuditStatus()), ResourceAudit::getAuditStatus, dto.getAuditStatus());
		wrapper.like(StrUtil.isNotBlank(dto.getResourceName()), ResourceAudit::getResourceName, dto.getResourceName());
		return resourceAuditService.pageList(page, wrapper);
    }

    @Operation(description = "详情")
    @GetMapping("/{id}")
    public R getById(@PathVariable("id") Long id) {
        return resourceAuditService.detail(id);
    }

    @Operation(description = "审核")
    @PostMapping("/audit")
    public R audit(@RequestBody ResourceAuditDto dto) {
        return resourceAuditService.audit(dto);
    }
}
